#include "productSummaryDlg.h"
#include "ui_ProductSummaryDlg.h"
#include "tabledefine.h"

extern QSqlDatabase ManagementDB;

ProductSummaryDlg::ProductSummaryDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ProductSummaryDlg)
{
    ui->setupUi(this);
    
    //Create database model
    model = new QSqlQueryModel;
    model->setQuery(QString("select * from %1").arg(DM_TABLE_NAME), ManagementDB);
    model->setHeaderData(1, Qt::Horizontal, "名称");
    model->setHeaderData(2, Qt::Horizontal, "厂家");
    model->setHeaderData(3, Qt::Horizontal, "订货号");
    model->setHeaderData(4, Qt::Horizontal, "媒质类型");
    model->setHeaderData(5, Qt::Horizontal, "应用");
    model->setHeaderData(6, Qt::Horizontal, "版本");
    model->setHeaderData(7, Qt::Horizontal, "数据库文件名");
    
    //Set database model and tableview
    ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);  //设置选中时选中一行
    ui->tableView->setModel(model);
    ui->tableView->hideColumn(0);  //隐藏id列(第0列)
    ui->tableView->resizeColumnsToContents();
    ui->tableView->verticalHeader()->hide();
    ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);//均分列
}

ProductSummaryDlg::~ProductSummaryDlg()
{
    delete ui;
}
